{extend name="public:layout" /}
{block name="title"}请假审批{/block}
{block name="head"}
<style>
    body{font-family: Arial,"Microsoft Yahei";}
</style>
{/block}
{block name="body"}
<div class="m-head-box">
    <a href="{:url('Index/index')}" class="left-link left-nav">
        <span class="iconfont icon-fanhui"></span>
    </a>
    <h2 class="title">请假审批</h2>
</div>
<div class="tabs wx_tabs">
    <a href="/system/op/index.html?mid=12&tpl=leave_apply&leave_status=0" {eq name="Request.param.leave_status" value="0"}class="active"{/eq}>待审核</a>
    <a href="/system/op/index.html?mid=12&tpl=leave_apply&leave_status=1" {eq name="Request.param.leave_status" value="1"}class="active"{/eq}>正在进行</a>
    <a href="/system/op/index.html?mid=12&tpl=leave_apply&leave_status=-1" {eq name="Request.param.leave_status" value="-1"}class="active"{/eq}>全部记录</a>
</div>
<article style="bottom: 0;" class="mescroll" id="mescroll">
    <div id="content-slide">

    </div>
</article>
<!--返回首页-->
<div class="back_index">
	<a href="/system">
		<img class="back_img" src="/public/mobile/static/images/back1.png" />
	</a>
</div>
{/block}
{block name="script"}
<script scr="/public/plugins/layer/layer.js"></script>
<script scr="/public/plugins/layerdate/layerdate.js"></script>
<script id="leave-tpl" type="text/html">
    <!--模板-->
    {{ each rows}}
    <div class="leave-item">
            <span class="name">
                请假人：{{ $value.driver_name}}

            </span>
            时间：{{ $value.leave_start_time }}-{{ $value.leave_end_time }}<br>
            原因： {{ $value.title }}
            {{ if $value.leave_status==2 }}
        <br>驳回：<span style="color:#ff0000">{{ $value.reject_reason }}</span>
            {{ /if }}
            <div class="action-box">
            {{ if $value.leave_status==0 }}
            <a href="javascript:;" onclick="applyAction(this)" data-status="1" data-aid="{{ $value.aid }}" data-driver="{{ $value.leave_uid }}" class="action-link apply-1">批准</a>
            <a href="javascript:;" onclick="applyAction(this)" data-status="2" data-aid="{{ $value.aid }}" class="action-link apply-2">驳回</a>
            {{ /if }}
            {{ if $value.leave_status==1 }}
            <a href="javascript:;" onclick="applyAction(this)" data-status="3" data-aid="{{ $value.aid }}" data-driver="{{ $value.leave_uid }}" data-endtime="{{ $value.leave_end_time }}" class="action-link apply-3">销假</a>
            {{ /if }}
            </div>
    </div>
    {{ /each }}
</script>
<script>
    $(function () {
        var leave_status="{$Request.param.leave_status}";
        initPage('content-slide','/system/logic.query/leaveList.html?mid=12',{leave_status:leave_status},'leave-tpl');
    });
    /*更新请假状态*/
    function applyAction(obj){
        In('layer',function () {
            var leave_status=$(obj).data('status');
            var leave_end_time=$(obj).data('endtime');
            var driver_uid=$(obj).data('driver');
            var data={aid:$(obj).data('aid'),mid:12,is_update:1,leave_status:leave_status};
            var url="{:url('logic.query/infoRecord')}";
            var driver_data={mid:16,is_update:1,driver_uid:driver_uid}
            /*同意*/
            if(leave_status==1){
                layer.confirm('确认审核通过吗？', {
                    scrollbar: false,
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.post(url,data,function (res) {
                        if(res.code==1){
                            driver_data.dri_status=1;
                            $.post(url,driver_data,function (data) {
                                if(data.code==1){
                                    layer.msg('审核通过',{time:1000},function () {
                                        rePage();
                                    })
                                }
                            })
                        }else{
                            layer.msg(res.msg,{time:1000});
                        }
                    })
                });
            }
            /*驳回*/
            if(leave_status==2){
                layer.prompt({title: '请输入驳回原因', formType: 2,scrollbar: false}, function(text, index){
                    data.reject_reason=text;
                    $.post(url,data,function (res) {
                        if(res.code==1){
                            layer.msg('请假已驳回',{time:1000},function () {
                                rePage();
                            })
                        }else{
                            layer.msg(res.msg,{time:1000});
                        }
                    })
                });

            }
            /*销假*/
            if(leave_status==3){
                var html='<div style="padding:30px;">' +
                    '<input class="form-control laydatetime" type="text"  style="height:30px;width:100%;border:1px solid #e8e8e8;" placeholder="请选择销假日期" id="changedate" name="leave_end_time" value="'+leave_end_time+'">' +
                    '</div>';
                layer.open({
                    type: 1,
                    title:'选择销假时间',
                    skin: 'layui-layer-rim', //加上边框
                    //area: ['420px', '300px'], //宽高
                    scrollbar: false,
                    content:html,
                    btn:['确定销假','取消'],
                    yes:function () {
                        data.leave_end_time=$('input[name="leave_end_time"]').val();
                        $.post(url,data,function (res) {
                            if(res.code==1){
                                driver_data.dri_status=2;
                                $.post(url,driver_data,function (data) {
                                    if(data.code==1){
                                        layer.msg('销假成功',{time:1000},function () {
                                            layer.closeAll();
                                            rePage();
                                        })
                                    }
                                })
                            }else{
                                layer.msg(res.msg,{time:1000});
                            }
                        })

                    }
                });
            }
            In('laydate',function () {
                laydate.render({
                    elem: '#changedate'
                    ,type: 'datetime'
                    ,min: 0 //7天前
                });
            })
        })
    }
</script>

{/block}